/* pppsmt03.p - ITEM SITE COST MAINTENANCE                              */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.15.1.8 $                                                         */
/* $Revision: 1.15.1.10 $                                                         */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 7.0     LAST MODIFIED: 08/28/91    BY: pma *F003*          */
/* REVISION: 7.0     LAST MODIFIED: 07/27/92    BY: pma *F782*          */
/* REVISION: 7.0     LAST MODIFIED: 10/05/92    BY: pma *G122*          */
/* REVISION: 7.3     LAST MODIFIED: 02/13/93    BY: pma *G032*          */
/* REVISION: 7.3     LAST MODIFIED: 04/22/93    BY: pma *GA11*          */
/* REVISION: 7.3     LAST MODIFIED: 06/15/93    BY: qzl *GC15***Rev Only*/
/* REVISION: 7.3     LAST MODIFIED: 08/12/93    BY: ram *GE15*          */
/* REVISION: 7.3     LAST MODIFIED: 11/04/93    BY: ais *GG86***Rev Only*/
/* REVISION: 7.3     LAST MODIFIED: 02/15/94    BY: pxd *FL60*          */
/* REVISION: 7.3     LAST MODIFIED: 06/28/94    BY: pxd *FP14*          */
/*           7.3                    09/03/94    BY: bcm *GL93*          */
/*           7.3                    09/11/94    BY: rmh *GM19*          */
/*           7.3                    09/21/94    BY: ljm *GM74*          */
/*           8.5                    10/18/94    BY: mwd *J034*          */
/*           7.3                    11/06/94    BY: rwl *GO27*          */
/*           7.2                    03/09/95    BY: qzl *F0M6*          */
/*           7.3                    07/13/95    BY: jzs *G0S6*          */
/*           7.3                    11/15/95    BY: str *G1B0*          */
/* REVISION: 8.6     LAST MODIFIED: 06/11/96    BY: aal *K001*          */
/*           8.5                    07/30/96    BY: jpm *J12Z*          */
/* REVISION: 8.6     LAST MODIFIED: 10/10/96    BY: svs *K007*          */
/* REVISION: 8.6     LAST MODIFIED: 07/05/97    BY: *J1PS* Felcy D'Souza */
/* REVISION: 7.4     LAST MODIFIED: 12/22/97    BY: *H1HP* Jean Miller  */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan    */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan    */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 05/12/00   BY: *N09X* Antony Babu      */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KQ* myb              */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.15.1.6  BY: Zheng Huang           DATE: 02/01/02  ECO: *P000*  */
/* Revision: 1.15.1.7  BY: Samir Bavkar          DATE: 05/01/02  ECO: *P060*  */
/* $Revision: 1.15.1.8 $        BY: John Corda            DATE: 08/09/02  ECO: *N1QP*  */
/* Revision: 1.15.1.8  BY: John Corda            DATE: 08/09/02  ECO: *N1QP*  */
/* $Revision: 1.15.1.10 $  BY: Piotr Witkowicz       DATE: 03/17/03  ECO: *P0NN*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/* ********** Begin Translatable Strings Definitions ********* */
&SCOPED-DEFINE pppsmt03_p_1 "Pri"
/* MaxLen: Comment: */
&SCOPED-DEFINE pppsmt03_p_2 "Category"
/* MaxLen: Comment: */
&SCOPED-DEFINE pppsmt03_p_3 " Item Price Data "
/* MaxLen: Comment: */
&SCOPED-DEFINE pppsmt03_p_4 "Lower Level"
/* MaxLen: Comment: */
&SCOPED-DEFINE pppsmt03_p_5 "A/O"
/* MaxLen: Comment: */
&SCOPED-DEFINE pppsmt03_p_8 "Element"
/* MaxLen: Comment: */
&SCOPED-DEFINE pppsmt03_p_9 "Total"
/* MaxLen: Comment: */
&SCOPED-DEFINE pppsmt03_p_10 "This Level"
/* MaxLen: Comment: */
/* ********** End Translatable Strings Definitions ********* */
{mfdtitle.i "99 "}

{cxcustom.i "PPPSMT03.P" }
{gldydef.i new}
{gldynrm.i new}
define new shared variable ppform as character.
define new shared variable promo_old like pt_promo.
define new shared variable part like in_part.
define new shared variable site like in_site label "Inventory Site".
define new shared variable frtitle as character format "x(24)".
define new shared variable csset like cs_set initial "".
define new shared variable s_mtl like sct_mtl_tl.
define new shared variable s_lbr like sct_lbr_tl.
define new shared variable s_bdn like sct_bdn_tl.
define new shared variable s_ovh like sct_ovh_tl.
define new shared variable s_sub like sct_sub_tl.
define new shared frame d.
define new shared frame d0.
define new shared frame d1. /*used by ppptmt03.p*/
define variable inrecno as recid no-undo.
define new shared variable transtype as character.
define new shared variable startrow as integer.
define new shared variable global_costsim like sc_sim.
define new shared variable global_category like sc_category.
define new shared workfile sptwkfl
   field element  like spt_element column-label {&pppsmt03_p_8}
   field primary  like mfc_logical column-label {&pppsmt03_p_1}
   field prim2    like mfc_logical
   field ao       like spt_ao      column-label {&pppsmt03_p_5}
   field cst_tl   like spt_cst_tl  column-label {&pppsmt03_p_10}
   field old_cst_tl like spt_cst_tl
   field cst_ll   like spt_cst_ll  column-label {&pppsmt03_p_4}
   field cst_tot  like spt_cst_tl  column-label {&pppsmt03_p_9}
   field cat_desc as character     column-label {&pppsmt03_p_2}
   field seq      like spt_pct_ll
   field part     like pt_part. {&PPPSMT03-P-TAG1}
define variable default-rule like slrd_linking_rule no-undo.
define variable default-gl-site like slrd_gl_cost_site no-undo.
define variable defined-gl-site like slrd_gl_cost_site no-undo.
define variable default-gl-set as character no-undo.
define variable mfg-err as integer no-undo.
define variable save-gl-site like slrd_gl_cost_site no-undo.
define variable save-gl-set like in_gl_set no-undo.
define variable save-cst-tot like sct_cst_tot no-undo.
define variable gl-set as character no-undo.
define variable clear-msg like mfc_logical no-undo.
define variable save-in-gl-site like in_gl_cost_site no-undo.
define variable new-inmstr like mfc_logical no-undo.
define variable rule_not_applied_txt as character format "x(20)" no-undo.
define variable rndmthd like gl_rnd_mthd no-undo.
rule_not_applied_txt = " - " + getTermLabel("RULE_NOT_APPLIED",20).
define buffer inmstr for in_mstr.
define buffer sctdet for sct_det.
define buffer sptdet for spt_det.
form
   {ppptmta1.i}
    site colon 19
    in_mstr.in_gl_cost_site colon 51
with frame a side-labels width 80 attr-space.
/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).
form {ppptmta5.i}
with frame d1 title color normal
   (getFrameTitle("ITEM_PRICE_DATA",23))
   side-labels width 80 attr-space.
/* SET EXTERNAL LABELS */
setFrameLabels(frame d1:handle).
form
   {ppptmta9.i}
with frame d ? down title color normal frtitle width 80 no-attr-space.
/* SET EXTERNAL LABELS */
setFrameLabels(frame d:handle).
form
   {ppptmta9.i}
with frame d0 1 down width 80 overlay row startrow no-labels
   title color normal (getFrameTitle("TOTALS",16)) no-attr-space.
view frame a.
view frame d.
display global_part @ pt_part global_site @ site with frame a.
mainloop:
repeat:
   if clear-msg then
   pause 0 no-message.
   prompt-for pt_part site with frame a no-validate
      editing:
      /* SET GLOBAL PART VARIABLE */
      global_part = input pt_part.
      global_site = input site.
      if frame-field = "pt_part" then do:
         /* FIND NEXT/PREVIOUS RECORD */
         {mfnp.i pt_mstr pt_part pt_part pt_part pt_part pt_part}
         if recno <> ? then do:
            display pt_part
               pt_desc1 pt_desc2 pt_um
            with frame a.
         end.
      end.
      else if frame-field = "site" then do:
         /* FIND NEXT/PREVIOUS RECORD */
         {mfnp.i si_mstr site si_site site si_site si_site}
         if recno <> ? then do:
            site = si_site.
            display site with frame a.
         end.
      end.
      else do:
         readkey.
         apply lastkey.
      end.
   end. /* PROMPT-FOR...EDITING */
   /* ADD/MODIFY */
   assign site.
   if not can-find (pt_mstr where pt_part = input pt_part) then do:
      clear-msg = no.
      {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3} /*ITEM NUMBER NOT AVAILABLE */
      undo, retry.
   end.
   if not can-find (si_mstr where si_site = site) then do:
      clear-msg = no.
      {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}  /* SITE DOES NOT EXIST */
      next-prompt site with frame a.
      undo, retry.
   end.
   find si_mstr where si_site = input site no-lock no-error.
   if available si_mstr and si_db <> global_db then do:
      clear-msg = no.
      {pxmsg.i &MSGNUM=5421 &ERRORLEVEL=3}
      /* SITE NOT ASSIGNED TO THIS DATABASE */
      next-prompt site with frame a.
      undo, retry.
   end.
   if available si_mstr then do:
      {gprun.i ""gpsiver.p""
         "(input si_site, input recid(si_mstr), output return_int)"}
      if return_int = 0 then do:
         clear-msg = no.
         {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
         /* USER DOES NOT HAVE ACCESS TO THIS SITE */
         next-prompt site with frame a.
         undo mainloop, retry mainloop.
      end.
   end.
   find pt_mstr exclusive-lock where pt_part = input pt_part no-error.
   if not available pt_mstr then do:
      clear-msg = no.
      {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}  /*ITEM NUMBER NOT AVAILABLE */
      undo, retry.
   end.
   pt_recno = recid(pt_mstr).
   display pt_desc1 pt_desc2 pt_um with frame a.
   new-inmstr = no.
     if not can-find(in_mstr where in_part = pt_part
      and in_site = site) then
      new-inmstr = yes.
   /* gpincr.p ROUTINE IS USED TO CREATE in_mstr RECORD. */
   {gprun.i ""gpincr.p"" "(input no,
        input pt_part,
        input site,
        input si_gl_set,
        input si_cur_set,
        input pt_abc,
        input pt_avg_int,
        input pt_cyc_int,
        input pt_rctpo_status,
        input pt_rctpo_active,
        input pt_rctwo_status,
        input pt_rctwo_active,
        output inrecno)"}
   clear-msg = yes.
   for first gl_ctrl fields(gl_rnd_mthd) no-lock:
   end.
   if available gl_ctrl then rndmthd = gl_rnd_mthd.
   for first icc_ctrl
      fields(icc_gl_set icc_cogs icc_gl_sum
          icc_gl_tran icc_mirror icc_jrnl)
   no-lock:
   end.
   for first in_mstr
      fields(in_part in_site in_gl_cost_site in_gl_set)
   no-lock where recid(in_mstr) = inrecno :
   end.
   display in_mstr.in_gl_cost_site with frame a.
   assign
      save-gl-site = in_mstr.in_gl_cost_site
      save-gl-set = (if in_mstr.in_gl_set <> "" then in_mstr.in_gl_set
      else icc_gl_set).
   /* SAVE THE OLD COST */
   find sct_det where sct_det.sct_part = in_mstr.in_part and
      sct_det.sct_site = in_mstr.in_gl_cost_site and
      sct_det.sct_sim = (if in_mstr.in_gl_set <> "" then
      in_mstr.in_gl_set
      else icc_gl_set)
   exclusive-lock no-error.
   if available sct_det then
      save-cst-tot = sct_cst_tot.
   else
      save-cst-tot = 0.
   /* TO CREATE CST-ADJ WHEN FIRST LINKING, save-cst-tot MUST BE 0 */
   if new-inmstr then
      save-cst-tot = 0.
   /* FIND DEFAULT LINKING RULE */
   run glCostSite
      (input  site,
      input  global_part,
      output default-gl-site,
      output default-gl-set,
      output default-rule,
      output defined-gl-site,
      output mfg-err).
   if default-rule > 0 then do:
      {pxmsg.i &MSGNUM=3849 &ERRORLEVEL=1
         &MSGARG1=default-rule &MSGARG2=defined-gl-site}
      /*LINKING RULE # : DEFAULT GL COST SOURCE SITE # */
   end.
   if mfg-err > 0 then do:
      if mfg-err = 3848 then do:
         for first inmstr fields(in_site) where
            inmstr.in_part = global_part and
            inmstr.in_gl_cost_site = site and
            inmstr.in_site <> inmstr.in_gl_cost_site
         no-lock:
         end.
         if available inmstr then do:
            {pxmsg.i &MSGNUM=3848 &ERRORLEVEL=1
               &MSGARG1=inmstr.in_site &MSGARG3=rule_not_applied_txt}
            /* INVENTORY SITE IS SOURCE SITE FOR SITE #*/
         end.
      end.
      else do:
         if not (default-rule = 1 and
            (mfg-err = 3845 or mfg-err = 3886)) and
            not (default-rule = 3 and site = in_mstr.in_gl_cost_site
            and site = defined-gl-site and
            (mfg-err = 3845 or mfg-err = 3886))
         then do:
            {pxmsg.i &MSGNUM=mfg-err &ERRORLEVEL=1
               &MSGARG1=rule_not_applied_txt}
            /* mfg-err could be 5421, 3847, 3886, 3845 or 3846 */
         end.
      end.
   end.
   /* THERE ARE 3 SCENARIOS WHERE UPDATE IS ALLOWED
   1. A DETAIL RULE WAS SET UP IN RULES MAINTENANCE.
   2. NO DTEAIL RULE BUT RULE MASTER IS ACTIVE.
   3. INVENTORY SITE AND GL COST SITE ARE DIFFERENT.
   */
   
   if (default-rule > 0 and mfg-err = 0) or
      (not can-find(first slrd_det where slrd_inventory_site = site)
      and can-find(first slr_mstr where slr_inventory_site = site
      and slr_lsc_active = yes)) or
      site <> input in_mstr.in_gl_cost_site
      then do
      on error undo, retry on endkey undo mainloop, retry mainloop:
         for first in_mstr fields(in_gl_cost_site)
         exclusive-lock where recid(in_mstr) = inrecno :
         end.
         save-in-gl-site = in_mstr.in_gl_cost_site.
         update in_mstr.in_gl_cost_site with frame a.
         if save-in-gl-site <> in_mstr.in_gl_cost_site and
            not ({gppswd.v &field = "in_mstr.in_gl_cost_site"}) then do:
            {pxmsg.i &MSGNUM=2186 &ERRORLEVEL=3}
            /* USER DOES NOT HAVE ACCESS TO THIS FIELD */
            next-prompt in_mstr.in_gl_cost_site.
            undo, retry.
         end.
         for first si_mstr fields(si_db si_gl_set)
            where si_site = in_mstr.in_gl_cost_site no-lock:
         end.
         if not available si_mstr
         then do:
            {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}  /* SITE DOES NOT EXIST */
            next-prompt in_mstr.in_gl_cost_site with frame a.
            undo, retry.
         end.
         if si_db <> global_db then do:
            {pxmsg.i &MSGNUM=5421 &ERRORLEVEL=3}
            /* SITE NOT ASSIGNED TO THIS DATABASE */
            next-prompt in_mstr.in_gl_cost_site with frame a.
            undo, retry.
         end.
         if site <> in_mstr.in_gl_cost_site then do:
            if default-rule = 0 then do:
               if can-find (first slr_mstr
                  where slr_inventory_site = site and slr_lsc_active)
               then do:
                  {pxmsg.i &MSGNUM=3887 &ERRORLEVEL=2}
                  pause.
                  /* NO MATCHING RULES EXIST FOR THIS INVENTORY SITE */
               end.
               else do:
                  {pxmsg.i &MSGNUM=3887 &ERRORLEVEL=3}
                  /* NO MATCHING RULES EXIST FOR THIS INVENTORY SITE */
                  /* ERROR WHEN NO ACTIVE RULES ELSE WARNING */
                  next-prompt in_mstr.in_gl_cost_site with frame a.
                  undo, retry.
               end.
            end.
            for first inmstr fields (in_part in_gl_cost_site in_gl_set)
               where inmstr.in_part = pt_part and
               inmstr.in_site = in_mstr.in_gl_cost_site no-lock:
            end.
            if not available inmstr then do:
               {pxmsg.i &MSGNUM=3886 &ERRORLEVEL=3}
               /*INVENTORY MASTER DOES NOT EXIST AT THIS SITE*/
               next-prompt in_mstr.in_gl_cost_site with frame a.
               undo, retry.
            end.
            in_mstr.in_gl_set = inmstr.in_gl_set.
            /* GL-SET IS GL COST SET NAME IN sct_sim AT NEW LINKED SITE */
            if in_mstr.in_gl_set = "" then
               gl-set = icc_gl_set.
            else
               gl-set = in_mstr.in_gl_set.
            for first sct_det where
               sct_part = inmstr.in_part and
               sct_site = inmstr.in_gl_cost_site and
               sct_sim = gl-set no-lock:
            end.
            if not available sct_det
            then do:
               {pxmsg.i &MSGNUM=3845 &ERRORLEVEL=3}
               /*GL COSTS DO NOT EXIST AT THIS SITE*/
               next-prompt in_mstr.in_gl_cost_site with frame a.
               undo, retry.
            end.
            if can-find(first cs_mstr where cs_set = inmstr.in_gl_set and
               cs_method = "AVG") then do:
               {pxmsg.i &MSGNUM=3846 &ERRORLEVEL=3}
               /*AVG COST NOT ALLOWED WITH LINKED SITE*/
               next-prompt in_mstr.in_gl_cost_site with frame a.
               undo, retry.
            end.
            for first inmstr fields(in_site) where
               inmstr.in_part = pt_part and
               inmstr.in_gl_cost_site = site and
               inmstr.in_site <> inmstr.in_gl_cost_site
            no-lock:
            end.
            if available inmstr then do:
               {pxmsg.i &MSGNUM=3848 &ERRORLEVEL=3 &MSGARG1=inmstr.in_site}
               /* INVENTORY SITE IS SOURCE SITE FOR SITE #*/
               next-prompt in_mstr.in_gl_cost_site with frame a.
               undo, retry.
            end.
            if can-find(first inmstr where inmstr.in_part = pt_part and
               inmstr.in_site = in_mstr.in_gl_cost_site and
               inmstr.in_site <> inmstr.in_gl_cost_site) then do:
               {pxmsg.i &MSGNUM=3847 &ERRORLEVEL=3}
               /* NOT A SOURCE COST SITE*/
               next-prompt in_mstr.in_gl_cost_site with frame a.
               undo, retry.
            end.
            if save-cst-tot <> sct_cst_tot then do:
               /* CREATE CST-ADJ TRANSACTION */
               trmsg = 5205.
               {gprun.i 'iccstinv.p'
                  "(input save-cst-tot,
                    buffer sct_det,
                    input 'CCHG',
                    input in_mstr.in_site,
                    input icc_cogs,
                    input icc_gl_sum,
                    input icc_gl_tran,
                    input icc_mirror,
                    input icc_jrnl,
                    input rndmthd,
                    input pt_part,
                    input pt_prod_line,
                    input pt_site,
                    input pt_um)"
                  }
            end.
         end. /* if site <> in_mstr.in_gl_cost_site */
         else
         /* UNLINKING COSTS; RESETTING COSTS BACK TO ITSELF */
         if save-gl-site <> in_mstr.in_gl_cost_site then do:
            in_mstr.in_gl_set = si_mstr.si_gl_set.
            find sct_det where sct_det.sct_part = in_mstr.in_part and
               sct_det.sct_site = in_mstr.in_gl_cost_site and
               sct_det.sct_sim =
               (if in_mstr.in_gl_set <> "" then in_mstr.in_gl_set
               else icc_gl_set)
            exclusive-lock no-error.
            /* IF NEW LINKED SITE HAS ZERO TOTAL COST OR NO COSTS,   */
            /* WE WILL COPY THE COSTS FROM PREVIOUS GL COST SITE.    */
            if available sct_det and sct_det.sct_cst_tot = 0 then do:
               find sctdet where sctdet.sct_part = in_mstr.in_part and
                  sctdet.sct_site = save-gl-site and
                  sctdet.sct_sim = save-gl-set no-lock no-error.
               if available sctdet then do:
                  assign
                     sct_det.sct_cst_tot = sctdet.sct_cst_tot
                     sct_det.sct_mtl_tl = sctdet.sct_mtl_tl
                     sct_det.sct_lbr_tl = sctdet.sct_lbr_tl
                     sct_det.sct_bdn_tl = sctdet.sct_bdn_tl
                     sct_det.sct_ovh_tl = sctdet.sct_ovh_tl
                     sct_det.sct_sub_tl = sctdet.sct_sub_tl
                     sct_det.sct_mtl_ll = sctdet.sct_mtl_ll
                     sct_det.sct_lbr_ll = sctdet.sct_lbr_ll
                     sct_det.sct_bdn_ll = sctdet.sct_bdn_ll
                     sct_det.sct_ovh_ll = sctdet.sct_ovh_ll
                     sct_det.sct_sub_ll = sctdet.sct_sub_ll
                     sct_det.sct_cst_date = today
                     .
                  for each spt_det exclusive-lock where
                        spt_det.spt_part = sct_det.sct_part and
                        spt_det.spt_site = sct_det.sct_site and
                        spt_det.spt_sim = sct_det.sct_sim:
                     find sptdet where
                        sptdet.spt_part = spt_det.spt_part and
                        sptdet.spt_site = save-gl-site and
                        sptdet.spt_sim = save-gl-set and
                        sptdet.spt_element = spt_det.spt_element
                     no-lock no-error.
                     if available sptdet then
                     assign
                        spt_det.spt_cst_tl = sptdet.spt_cst_tl
                        spt_det.spt_cst_ll = sptdet.spt_cst_ll
                        .
                  end. /* for each spt_det ... */
               end. /* if available sctdet then do: */
               /* NO CST-ADJ REQ'D; COST SAME; COPIED FROM OLD LINK */
            end. /* if available sct_det and sct_det.sct_cst_tot = 0 */
            else if not available sct_det and not new-inmstr then do:
               /* OLD GL COST DELETED BY REFRESH UTILITY */
               find sctdet where sctdet.sct_part = in_mstr.in_part and
                  sctdet.sct_site = save-gl-site and
                  sctdet.sct_sim = save-gl-set no-lock no-error.
               if available sctdet then do:
                  create sct_det.
                  assign
                     sct_det.sct_part = sctdet.sct_part
                     sct_det.sct_site = in_mstr.in_gl_cost_site
                     sct_det.sct_sim =
                     (if in_mstr.in_gl_set <> "" then
                     in_mstr.in_gl_set
                     else icc_gl_set)
                     sct_det.sct_cst_tot = sctdet.sct_cst_tot
                     sct_det.sct_mtl_tl = sctdet.sct_mtl_tl
                     sct_det.sct_lbr_tl = sctdet.sct_lbr_tl
                     sct_det.sct_bdn_tl = sctdet.sct_bdn_tl
                     sct_det.sct_ovh_tl = sctdet.sct_ovh_tl
                     sct_det.sct_sub_tl = sctdet.sct_sub_tl
                     sct_det.sct_mtl_ll = sctdet.sct_mtl_ll
                     sct_det.sct_lbr_ll = sctdet.sct_lbr_ll
                     sct_det.sct_bdn_ll = sctdet.sct_bdn_ll
                     sct_det.sct_ovh_ll = sctdet.sct_ovh_ll
                     sct_det.sct_sub_ll = sctdet.sct_sub_ll
                     sct_det.sct_cst_date = today
                     .
                  if recid(sct_det) = -1 then .
                  for each sptdet where
                        sptdet.spt_part = sctdet.sct_part and
                        sptdet.spt_site = save-gl-site and
                        sptdet.spt_sim = save-gl-set
                     no-lock:
                     create spt_det.
                     assign
                        spt_det.spt_part = sptdet.spt_part
                        spt_det.spt_site = in_mstr.in_gl_cost_site
                        spt_det.spt_sim =
                        (if in_mstr.in_gl_set <> "" then
                        in_mstr.in_gl_set
                        else icc_gl_set)
                        spt_det.spt_element = sptdet.spt_element
                        spt_det.spt_cst_tl = sptdet.spt_cst_tl
                        spt_det.spt_cst_ll = sptdet.spt_cst_ll
                        spt_det.spt_pct_ll = sptdet.spt_pct_ll
                        .
                     if recid(spt_det) = -1 then .
                  end. /* for each sptdet */
                  /* NO CST-ADJ REQ'D; COST SAME; COPIED FROM OLD LINK */
               end. /* if available sctdet then do: */
            end. /* if not available sct_det */
            else
            if available sct_det and
               save-cst-tot <> sct_det.sct_cst_tot
            then do:
               /* CREATE CST-ADJ TRANSACTION */
               trmsg = 5205.
               {gprun.i 'iccstinv.p'
                  "(input save-cst-tot,
                    buffer sct_det,
                    input 'CCHG',
                    input in_mstr.in_site,
                    input icc_cogs,
                    input icc_gl_sum,
                    input icc_gl_tran,
                    input icc_mirror,
                    input icc_jrnl,
                    input rndmthd,
                    input pt_part,
                    input pt_prod_line,
                    input pt_site,
                    input pt_um)"
                  }
            end.
         end. /* if save-gl-site <> in_mstr.in_gl_cost_site then do: */
      end. /* on error undo, retry ... */
      if not can-find(first sct_det where sct_part = pt_part and
         sct_site = site) then do:
         {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1} /* ADDING NEW RECORD */
         pause 1.
      end.
      ppform = "d2".
      startrow = frame-row(d). /* ppptmtd.p will repaint d0 & d */
      {gprun.i ""ppptmtd.p""}
      hide frame d0.
      hide frame d.
      frtitle = getFrameTitle("GL_COST_DATA",18).
      view frame d.
   end.
PROCEDURE GLCostSite:
/* -------------------------------------------------------------
  Purpose: This internal procedure determines the default GL
           cost site, GL cost set name and Linking rule.
  Parameters:
            input  site            (Inventory Site)
            input  part            (Part Number
            output gl-site         (GL Cost Site)
            output set-name        (GL cost set name)
            output rule            (Linking Rule)
            output defined-gl-site (Defined GL Cost Site)
            output mfg-err         (Mfg/Pro error number)
  Notes:   This is called from the main procedure when the
           Inventory site is changed(or updated).
----------------------------------------------------------------*/
define input  parameter site            as character  no-undo.
define input  parameter part            as character  no-undo.
define output parameter gl-site         as character  no-undo.
define output parameter set-name        as character  no-undo.
define output parameter rule            as integer    no-undo.
define output parameter defined-gl-site as character no-undo.
define output parameter mfg-err         as integer    no-undo.
define buffer si_mstr for si_mstr.
define buffer pt_mstr for pt_mstr.
define buffer ptp_det for ptp_det.
define buffer in_mstr for in_mstr.
define buffer sct_det for sct_det.
define buffer cs_mstr for cs_mstr.
   do for si_mstr, pt_mstr, ptp_det, in_mstr, sct_det, cs_mstr :
      {gpingl.i}
   end. /* do for */
end.
